package com.fjec.common.aspect;


import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.LinkedHashMap;
import java.util.Map;

public class BaseAspect {

    protected Map<String, Object> getParameters(String[] argsNames, Object[] argsValues) {
        Map<String, Object> argsMap = new LinkedHashMap<>();
        for (int i = 0; i < argsNames.length; i++) {
            String argsName = argsNames[i];
            if (argsValues[i] != null) {
                if (argsValues[i] instanceof MultipartFile[]) {
                    argsValues[i] = "fileArray";
                } else if (MultipartFile.class.isAssignableFrom(argsValues[i].getClass())) {
                    String fileName = ((MultipartFile) argsValues[i]).getOriginalFilename();
                    argsValues[i] = fileName;
                } else if (ServletResponse.class.isAssignableFrom(argsValues[i].getClass())) {
                    String value = "ServletResponse";
                    argsValues[i] = value;
                } else if (ServletRequest.class.isAssignableFrom(argsValues[i].getClass())) {
                    String value = "ServletRequest";
                    argsValues[i] = value;
                }
            }
            argsMap.put(argsName, argsValues[i]);
        }
        return argsMap;
    }
}
